//
//  GoodsDetailSelectSkuPopViewBottomView.m
//  ABSallRec
//
//  Created by 我演示 on 2019/11/14.
//  Copyright © 2019 Jerry-Fu. All rights reserved.
//

#import "GoodsDetailSelectSkuPopViewBottomView.h"

@interface GoodsDetailSelectSkuPopViewBottomView ()
/**数量label*/
@property(nonatomic,weak) UILabel *countLabel ;

/**数量减少btn   */
@property(nonatomic,weak) UIButton  *leftDeletBtn ;

/**textField*/
@property(nonatomic,weak) UITextField *countTextField ;

/**数量增加的lbtn*/
@property(nonatomic,weak) UIButton *rightAddBtn ;

/**记录数量*/
@property(nonatomic,assign) NSInteger  countInteger ;

@end

@implementation GoodsDetailSelectSkuPopViewBottomView

-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame: frame]) {
        self.countInteger = 1;
        [self makeUpUI];
        [self makeUpSubviews];
    }
    return self;
}

-(void)makeUpUI {
    UILabel *countLabel =[[ UILabel alloc] initWithTextString:@"数量:" andTextColor:[UIColor colorWithHexString:@"#000000"] andTextFont:15];
    countLabel.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:15];
    [self addSubview:countLabel];
    self.countLabel = countLabel;
    
    //2 : 左侧减少的按钮
    UIButton *leftDeleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftDeleteBtn setImage:[UIImage imageNamed:@"goodssku_close"] forState:UIControlStateNormal];
    [leftDeleteBtn addTarget:self action:@selector(pressDeleteBtn) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:leftDeleteBtn];
    self.leftDeletBtn = leftDeleteBtn ;
    
    // 中间的textField
    UITextField *textField = [[UITextField alloc] init];
    textField.backgroundColor =    [UIColor colorWithHexString:@"#F4F4F4"];
    textField.textAlignment = NSTextAlignmentCenter;
     textField.layer.borderColor=[[UIColor greenColor] CGColor];
    textField.layer.masksToBounds = YES;
    textField.layer.cornerRadius = 3;
    textField.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.countInteger];
    [self addSubview:textField];
    self.countTextField = textField;
    // 右侧的按钮
    UIButton *rightAddBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [rightAddBtn  setImage:[UIImage imageNamed:@"goodssku_close"] forState:UIControlStateNormal];
    [rightAddBtn addTarget:self action:@selector(pressAddBtn) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:rightAddBtn ];
    self.rightAddBtn = rightAddBtn  ;
    
}

-(void)pressDeleteBtn {
    if (self.countInteger > 1) {
        self.countInteger -- ;
         self.countTextField.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.countInteger];
    }else {

        [ABSToastHUD showToast:@"不能再少了" afterDelayTime:1.0];

    }
   
}
-(void)pressAddBtn {
    self.countInteger ++;
    self.countTextField.text = [NSString stringWithFormat:@"%lu",(unsigned long)self.countInteger];
}

-(void)makeUpSubviews {
    
    [self.countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(15);
        make.top.bottom.equalTo(self).offset(0);
        make.width.offset(35);
    }];
    
    // 左侧的按钮
    [self.leftDeletBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.countLabel.mas_right).offset(13);
        make.centerY.equalTo(self.countLabel.mas_centerY).offset(0);
        make.width.offset(29);
        make.height.offset(29);
    }];
    
    //中间的textField
    [self.countTextField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.leftDeletBtn.mas_right).offset(2);
        make.centerY.equalTo(self.leftDeletBtn.mas_centerY).offset(0);
        make.width.offset(33);
        make.height.offset(29);
    }];
    
    
    // 右侧的按钮
    [self.rightAddBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.countTextField.mas_right).offset(2);
         make.centerY.equalTo(self.leftDeletBtn.mas_centerY).offset(0);
            make.width.offset(29);
            make.height.offset(29);
    }];
}


@end
